package com.fhz.day005;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    private EditText edit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        edit = (EditText) findViewById(R.id.edit);

        FragmentManager supportFragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();
        fragmentTransaction.add(R.id.ll,new ContentFragment());
        fragmentTransaction.commit();

    }

    public void send(View view) {
        FragmentManager supportFragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();
//        fragmentTransaction.add(R.id.ll,new ContentFragment());

        ContentFragment contentFragment = new ContentFragment();

        Bundle bundle = new Bundle();
        bundle.putString("inputText",edit.getText().toString());

        //设置bundle
        contentFragment.setArguments(bundle);

        //替换一个新的fragment
        fragmentTransaction.replace(R.id.ll,contentFragment);

        fragmentTransaction.commit();
    }
}